package com.jindy.module.dict.controller;

import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.core.page.TableDataInfo;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.module.dict.domain.Region;
import com.jindy.module.dict.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 地区Controller
 *
 * @author minjunjie
 * @date 2021-06-28
 */
@RestController
@RequestMapping("/region")
public class RegionController extends BaseController {
    @Autowired
    private RegionService regionService;

    /**
     * 查询地区列表
     */
//    @PreAuthorize("@ss.hasPermi('assets:region:list')")
    @GetMapping("/list")
    public TableDataInfo list(Region region) {
        startPage();
        List<Region> list = regionService.selectRegionList(region);
        return getDataTable(list);
    }

    /**
     * 导出地区列表
     */
//    @PreAuthorize("@ss.hasPermi('assets:region:export')")
    @GetMapping("/export")
    public AjaxResult export(Region region) {
        List<Region> list = regionService.selectRegionList(region);
        ExcelUtil<Region> util = new ExcelUtil<Region>(Region.class);
        return util.exportExcel(list, "region");
    }

    /**
     * 获取地区详细信息
     */
//    @PreAuthorize("@ss.hasPermi('assets:region:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(regionService.selectRegionById(id));
    }

    /**
     * 获取地区列表
     */
    @PostMapping("/regionList")
    public TableDataInfo regionList(Region region) {
        List<Map<String, Object>>  arrayProvinceList = regionService.selectTreeList();
        return getDataTable(arrayProvinceList);
    }
}
